package com.xh.hongaicodegenerator.core.saver;

import cn.hutool.core.util.StrUtil;
import com.xh.hongaicodegenerator.ai.genresult.HtmlCodeResult;
import com.xh.hongaicodegenerator.exception.BusinessException;
import com.xh.hongaicodegenerator.exception.ErrorCode;
import com.xh.hongaicodegenerator.model.enums.CodeGenTypeEnum;

public class HtmlCodeFileSaver extends CodeFileSaverTemplate<HtmlCodeResult>{
    @Override
    protected void saveFiles(HtmlCodeResult result, String baseDirPath) {
        writeToFile(baseDirPath, "index.html", result.getHtmlCode());
    }

    @Override
    protected CodeGenTypeEnum getCodeType() {
        return CodeGenTypeEnum.HTML;
    }

    @Override
    protected void  validateInput(HtmlCodeResult result){
        super.validateInput(result);
        if (StrUtil.hasBlank(result.getHtmlCode())){
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"HTML代码不能为空");
        }
    }
}
